package com.wwx.demo.dao.impl;

import com.wwx.demo.dao.BaseDao;
import com.wwx.demo.dao.api.TigerDao;
import com.wwx.demo.entity.Tiger;

import java.util.List;

public class TigerDaoImpl extends BaseDao implements TigerDao {
    @Override
    public List<Tiger> selectAllTigerList() {
        String sql = "select tiger_id tigerId,tiger_name tigerName,tiger_age tigerAge,tiger_salary tigerSalary from t_tiger";
        return selectList(sql, Tiger.class);
    }

    @Override
    public Tiger selectTigerById(String tigerId) {
        String sql = "select tiger_id tigerId,tiger_name tigerName,tiger_age tigerAge,tiger_salary tigerSalary from t_tiger where tiger_id = ?";
        return selectOne(sql, Tiger.class, tigerId);
    }

    @Override
    public void delectById(String tigerId) {
        String sql = "delete from t_tiger where tiger_id = ?";
        commonUpdate(sql, tigerId);
    }

    @Override
    public void insertTiger(Tiger tiger) {
        String sql = "insert into t_tiger (tiger_name,tiger_age,tiger_salary) values(?,?,?)";
        commonUpdate(sql, tiger.getTigerName(), tiger.getTigerAge(), tiger.getTigerSalary());
    }

    @Override
    public void updateTiger(Tiger tiger) {
        String sql = "update t_tiger set tiger_name = ?,tiger_age = ?,tiger_salary = ? where tiger_id = ?";
        commonUpdate(sql, tiger.getTigerName(), tiger.getTigerAge(), tiger.getTigerSalary(), tiger.getTigerId());
    }
}
